package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.StudentMapper;
import com.itheima.pojo.ClazzOption;
import com.itheima.pojo.JobOption;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 员工职位人数统计
     *
     * @return
     */
    @Override
    public JobOption getEmpJobDate() {
        List<Map> mapList = empMapper.getEmpJobData();


        List<Object> jobList = mapList.stream().map((map) ->
                map.get("job")).collect(Collectors.toList());
        List<Object> dateList = mapList.stream().map((map) ->
                map.get("total")).collect(Collectors.toList());
        JobOption jobOption = new JobOption(jobList, dateList);

        return jobOption;
    }

    /**
     * 员工性别人数统计
     *
     * @return
     */
    @Override
    public List<Map> getEmpGenderDate() {
        List<Map> genderList = empMapper.getEmpGenderData();
//        System.out.println(genderList);
        return genderList;
    }

    /*贾巨龙
     * 学员学历信息统计
     *
     * @return
     */
    @Override
    public List<Map> getStudentDegreeData() {
        List<Map> degreeList = studentMapper.getStudentDegreeData();
        return degreeList;
    }

    /**
     * 班级人数统计
     *
     * @return
     */
    @Override
    public ClazzOption getStudentClazzData() {
        List<Map> mapList = studentMapper.getStudentclazzData();


        List<Object> clazzList = mapList.stream().map((map) ->
                map.get("clazz")).collect(Collectors.toList());
        List<Object> dataList = mapList.stream().map((map) ->
                map.get("data")).collect(Collectors.toList());
        ClazzOption clazzOption = new ClazzOption(clazzList, dataList);

        return clazzOption;
    }


}
